import config from 'config'
import httpFetch from 'share/httpFetch'
import { message } from 'antd'

const airTicketServer = (context) => {
  return {

    // 询价列表
    async getAirTicketListData(params){
      try {
        context.setState({loading: true});
        const response = await httpFetch.post(`/open/order/api/international/flight/rfpList`,params);
        response.data.rows = response.data.body || [];
        return response;
      }catch (err) {
        dealWithErrorMes(err);
      }finally {
        context.setState({loading: false});
      }
    },
    // 询价详情
    async getDetailData(rfpId){
      try {
        context.setState({loading: true});
        const response = await httpFetch.get(`/open/order/api/international/flight/supplierRfpDetail/${rfpId}`);
        return response;
      }catch (err) {
        dealWithErrorMes(err);
      }finally {
        context.setState({loading: false});
      }
    },
    // 添加报价保存
    async quotationAdd(params){
      try {
        context.setState({loading: true});
        const response = await httpFetch.post(`/open/order/api/international/flight/saveRfpSupplierQuotationScheme`, params);
        return response;
      }catch (err) {
        dealWithErrorMes(err);
      }finally {
        context.setState({loading: false});
      }
    },
    // 航段获取
    async quotationHD(id){
      try {
        context.setState({loading: true});
        const response = await httpFetch.get(`/open/order/api/international/flight/rfpSupplierQuotationSchemeDetail/${id}`);
        return response;
      }catch (err) {
        dealWithErrorMes(err);
      }finally {
        context.setState({loading: false});
      }
    },
    // 操作报价状态
    async quotationChangeStatus(id, status, reason){
      try {
        context.setState({loading: true});
        let params = {
          "schemeId": id,
          "status": status,
          "failureReason": reason || ""
        }
        const response = await httpFetch.post(`/open/order/api/international/flight/updateRfpSupplierQuotationSchemeStatus`, params);
        return response;
      }catch (err) {
        dealWithErrorMes(err);
      }finally {
        context.setState({loading: false});
      }
    },
  }
}

const dealWithErrorMes = (err) => {
  message.error(`error:${err.response.data.message}`);
}

export default airTicketServer;
